<template>

  <!--登录内容-->
  <div class="login_container">

    <div class="login_box">
      <!--头像-->
      <div class="avatar_box">
        <img src="../assets/img/keai.gif"/>
      </div>

      <!--表单内容-->
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-width="0px" class="login_form">
        <!--用户名-->
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" placeholder="请输入用户名" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <!--密码-->
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" placeholder="请输入密码" prefix-icon="el-icon-lock"></el-input>
        </el-form-item>
        <!--验证码-->
        <el-form-item prop="verifycode">
          <div class="verify_box">
            <el-input v-model="loginForm.verifycode" placeholder="请输入验证码" prefix-icon="el-icon-mobile"
                      class="verify_code"></el-input>
            <img src="../assets/img/msFXK1.gif" class="verify_img"/>
          </div>
        </el-form-item>
        <el-form-item class="login_btn">
          <el-button type="primary" @click="submitForm('loginForm')">立即登录</el-button>
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  // export default {
  //
  // },
  export default {
    name: "login",
    data() {
      return {
        loginForm: {
          username: '',
          password: '',
          verifycode: ''
        },
        loginRules: {
          username: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {min: 3, max: 16, message: "长度在3到16个字符", trigger: 'blur'}],
          password: [{required: true, message: "请输入密码", trigger: 'blur'},
            {min: 3, max: 16, message: "长度在3到16个字符", trigger: 'blur'}],
          verifycode: [{required: true, message: "请输入验证码", trigger: 'blur'}]
        }
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            //  登录成功跳转到主页面
            this.$router.push("/main")
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="less" scoped>
  .login_container {
    height: 100%;
    background-color: aquamarine;
  }

  .login_box {
    height: 400px;
    width: 380px;
    background-color: aliceblue;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 55%;
    transform: translate(-50%, -50%);

    .avatar_box {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      border: 1px solid #EEEEEE;
      padding: 10px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); // 投影
      margin: -65px auto;
      background-color: #FFFFFF;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #EEEEEE;
      }
    }

    .login_form {
      position: absolute;
      bottom: 50px;
      width: 100%;
      padding: 0px 10px;
      box-sizing: border-box;

      .login_btn {
        display: flex;
        justify-content: center;
      }
      .verify_code {
        width: 200px;
      }

      .verify_box {
        display: flex;
        .verify_code {
          width: 70%;
          justify-content: left;
        }
        .verify_img {
          width: 30%;
          height: 40px;
          justify-content: flex-end;
        }
      }
    }

  }
</style>
